package com.shuai.shuaisecondhand_springboot.service;

import com.shuai.shuaisecondhand_springboot.entity.Collection;
import com.shuai.shuaisecondhand_springboot.mapper.CollectionMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CollectionService {

    @Autowired
    CollectionMapper collectionMapper;

    //根据用户id查找数据
    public List<Collection> findCollection(String Uid, String name) {
        return collectionMapper.findCollection(Uid, name);
    }

    //查询Sid的所有数据量
    public int getSidTotal(String Uid, String name) {
        return collectionMapper.getSidTotal(Uid, name);
    }

    //根据用户id和商品id查找数据
    public Boolean findMyCollection(@Param("Uid") String Uid, @Param("Gid") String Gid) {
        if (collectionMapper.findMyCollection(Uid, Gid) != null) {
            return true;
        } else {
            return false;
        }
    }

    //插入
    public Boolean insertCollection(@Param("Uid") String Uid, @Param("Gid") String Gid) {
        try {
            return collectionMapper.insertCollection(Uid, Gid);
        } catch (Exception e) {
            return false;
        }
    }

    //删除
    public Integer deleteCollection(long Uid, long Gid) {
        return collectionMapper.deleteCollection(Uid, Gid);
    }
}
